<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta charset="utf-8">
<title>学生家长对应关系导入</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../layui/css/layui.css" media="all">
</head>
<style>
.importParents {
	padding: 0px 15px 50px 15px;
}

.importParents .layui-table-view {
	border: none;
}

.importParents .importParents-con {
	height: 60px;
	padding: 15px 10px 0px 10px;
	background-color: rgb(242, 242, 242);
}

.importParents .importParents-con .leftbtn {
	float: left;
	margin-left: 10px;
}

.importParents .importParents-con .rightbtn {
	float: right;
	margin-right: 10px;
}

.importParents .importParents-con .savebtn {
	float: left;
	margin-left: 10px;
}

.importParents .layui-table-body table tbody .layui-table-hover {
	background: #fffdd3 !important;
}

.importParents .layui-table-body table tbody .layui-table-click {
	background: #fdef9b !important;
}

.importParents .layui-table-box {
	margin-top: 10px;
	border-bottom: 1px solid #E6E6E6;
}

.importParents .importParents-con .layui-form-select dl dd.layui-this{
	background-color: #1E9FFF !important;
}
</style>
<body>
	<div class="importParents">
		<div class="layui-block importParents-con">
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<div class="layui-input-inline">
					    <select name="stage" id="stage" lay-filter="stage">
					    	<option value=''>请选择阶段</option>
						</select>
					</div>
					<div class="layui-input-inline">
					    <select name="school" id="school" lay-filter="school">
					    	<option value=''>请先选择学校</option>
						</select>
					</div>
					<div class="layui-input-inline">
					    <select name="gradename" id="gradename" lay-filter="gradename">
					    	<option value=''>请选择年级</option>
						</select>
					</div>
					<div class="layui-input-inline">
					    <select name="classid" id="classid" lay-filter="classid">
					    	<option value=''>请选择班级</option>
						</select>
					</div>
					<button type="button" class="layui-btn layui-btn-normal leftbtn" id="btnselExcel">
						<i class="layui-icon"></i>选择Excel文件
					</button>
					<button type="button" class="layui-btn layui-btn-normal leftbtn" id="selExcel" style="display: none;">
						<i class="layui-icon"></i>选择Excel文件
					</button>
					
					<button type="button" class="layui-btn layui-btn-normal savebtn layui-disabled" disabled="disabled" lay-submit="" lay-filter="btnsaveparstu" id="btnsaveparstu">保存</button>
					<!-- <a href="/upload/templateDownload/学生信息表.xls" class="layui-btn layui-btn-primary rightbtn">下载模板</a> -->
				</div>
			</form>
		</div>
		<table class="layui-hide" id="teacher"></table>
	</div>
	<script src="../layui/layui.all.js" charset="utf-8"></script>
	<script src="../js/jquery-3.3.1.js"></script>
	<script src="../js/until/loading.js"></script>
	<script src="../js/until/loadingClass.js" ></script>
	<script>
		layui.use([ 'table', 'upload' ], function() {
			var $ = layui.jquery, upload = layui.upload, table = layui.table, form = layui.form;
			
			//加载阶段下拉框
			loadstage("stage", form);
		
			//根据阶段加载学校，年级下拉框
			form.on('select(stage)', function(data) {
				//年级下拉框
				loadgrade(data.value, "gradename", form);
				//学校下拉框
				loadSchool(data.value, "school", form);
		
			});
		
			//根据年级和学校加载班级下拉框
			form.on('select(gradename)', function(data) {
		
				var schoolid = $("#school").val();
				if (schoolid == null || schoolid == "" || schoolid == "0") {
					layer.alert('请先选择学校！', {
						icon: 2
					});
					return;
				}
				//班级下拉框加载
				loadClass(schoolid, data.value, "classid", form);
		
			});
			
			$("#btnselExcel").click(function(){
				var gradename = $("#gradename").val();
				var classid = $("#classid").val();
				if(gradename != "" && gradename != "00" && gradename != "0" && gradename != null && classid != "" && classid != "00" && classid != "0" && classid != null){
					$("#selExcel").click();
					$("#btnsaveparstu").attr("disabled", false); 
					$("#btnsaveparstu").removeClass("layui-disabled");
				}else{ 
					$("#btnsaveparstu").attr("disabled", true); 
					$("#btnsaveparstu").addClass("layui-disabled");
					layer.alert('请先选择班级！', {
						icon: 2
					});
				}
			});

			$("#selExcel").click(function(){
				var classid = $("#classid").val();
				var schoolid = $("#school").val();
				//指定允许上传的文件类型
				upload.render({ //允许上传的文件后缀
					elem : '#selExcel',
					url : '../sysparentmanagement/getexceltablelist?classid=' + classid + '&schoolid=' + schoolid,
					accept : 'file', //普通文件
					exts : 'xls|xlsx|xlsm', //只允许上传压缩文件
					acceptMime : 'xls|xlsx|xlsm',
					done : function(res) {
						if (res.code == 0) {
							table.render({
								elem : '#teacher',
								url : '../sysparentmanagement/excelloadtable?op=0',
								title : '家长学生数据表',
								skin : 'line',
								even : true,
								cols : [ [  {
									type : 'numbers',
									title : '编号'
								}, {
									field : 'stuid',
									title : '学生账号',
									align : 'center'
								}, {
									field : 'stuRealName',
									title : '学生姓名',
									align : 'center'
								}, {
									field : 'stuSex',
									title : '学生性别',
									align : 'center'
								}, {
									field : 'parRealName',
									title : '姓名',
									align : 'center'
								}, {
									field : 'parSex',
									title : '性别',
									align : 'center'
								}, {
									field : 'phone',
									title : '电话',
									align : 'center'
								}, {
									field : 'relation',
									title : '关系',
									align : 'center'
								}, {
									field : 'className',
									title : '学生班级',
									align : 'center'
								}, {
									field : 'gradename',
									title : '学生年级',
									align : 'center'
								} ] ]
							});
						} else {
							layer.alert(data.msg, {icon: 2});
						}
					}
				});
			});
			
			$("#btnsaveparstu").click(function() {
				var index = layer.load(0, {
					shade: 0.1
				});
				var schoolid = $("#school").val();
				$.ajax({
					type : 'get',
					url : '../sysparentmanagement/savestulist?schoolid=' + schoolid,
					datatype : 'json',
					success : function(data) {
						if (data.code == 0) {
							layer.close(index);
							layer.alert(data.msg, {icon: 1});
						} else {
							layer.close(index);
							layer.alert("存在重复数据或出现其他异常，数据导入失败，列表信息已替换为出现错误的信息，请核实信息后重试！", {icon: 2});
							table.render({
								elem : '#teacher',
								url : '../sysparentmanagement/excelloadtable?op=1',
								title : '家长学生数据表',
								skin : 'line',
								even : true,
								cols : [ [  {
									type : 'numbers',
									title : '编号'
								}, {
									field : 'stuid',
									title : '学生账号',
									align : 'center'
								}, {
									field : 'stuRealName',
									title : '学生姓名',
									align : 'center'
								}, {
									field : 'stuSex',
									title : '学生性别',
									align : 'center'
								}, {
									field : 'parRealName',
									title : '姓名',
									align : 'center'
								}, {
									field : 'parSex',
									title : '性别',
									align : 'center'
								}, {
									field : 'phone',
									title : '电话',
									align : 'center'
								}, {
									field : 'relation',
									title : '关系',
									align : 'center'
								}, {
									field : 'className',
									title : '学生班级',
									align : 'center'
								}, {
									field : 'gradename',
									title : '学生年级',
									align : 'center'
								} ] ]
							});
						}
					},
					error : function() {
						layer.close(index);
						layer.alert('访问失败，请重试！', {icon: 2});
					}
				});

			});
		});
	</script>
</body>

</html>